home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 04 / v_startu.c < prev    next >
C/C++ Source or Header  |  1991-05-03  |  2KB  |  50 lines

  1. /*    v_startup.c- Start-up and Shut-down the Video System */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <tools/viewport.h>
  6.  
  7. static int Old_mode = LASTMODE; /* startup video mode, Return to this
  8.                                  * mode when the window system exits.
  9.                                  */
  10. static unsigned Times_called = 0;
  11. /*----------------------------------------------------------------------*/
  12. void v_shutdown ( void )
  13. {
  14.     /* V_shutdown shuts down the video system sometime before the
  15.      * normal shutdown at program termination.
  16.      */
  17.  
  18.     if( Old_mode != LASTMODE )
  19.     {
  20.         textmode( Old_mode );   /* Restore original mode */
  21.         Old_mode = LASTMODE;
  22.     }
  23.     Times_called = 0;           /* allow a restart */
  24. }
  25.  
  26. int v_startup( int mode )
  27. {
  28.     /* v_startup is passed either a video mode or LASTMODE, as defined in
  29.      * <conio.h>, if mode==LASTMODE, the current video mode is used.
  30.      *
  31.      * V_startup calls atexit(), so the video system will shut down
  32.      * automatically when the program exits. The video system can
  33.      * be initialized only once. Subsequent calls do nothing & return false
  34.      * unless the video system is shut down explicitly with a
  35.      * v_shutdown() call.
  36.      */
  37.  
  38.     struct text_info info;
  39.  
  40.     if( Times_called++ == 0)
  41.     {
  42.         gettextinfo( &info );
  43.         Old_mode = info.currmode;
  44.         if( mode != LASTMODE )
  45.             textmode( mode );
  46.         atexit( v_shutdown );   /* Call v_shutdown on exit */
  47.     }
  48.     return( Times_called == 1 );
  49. }
  50.